package cn.com.bluemoon.daps.system.service.impl;

import cn.com.bluemoon.daps.system.entity.DapSysRoleMenu;
import cn.com.bluemoon.daps.system.mapper.DapSysRoleMenuMapper;
import cn.com.bluemoon.daps.system.service.DapSysRoleMenuService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色菜单关联表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2022-12-19
 */
@Slf4j
@Service
public class DapSysRoleMenuServiceImpl extends ServiceImpl<DapSysRoleMenuMapper, DapSysRoleMenu>
        implements DapSysRoleMenuService {

    @Override
    public boolean batchSave(Long roleId, List<Long> menuIdList){
        List<DapSysRoleMenu> list = menuIdList.stream().map(m -> {
            DapSysRoleMenu sysRoleMenu = new DapSysRoleMenu();
            sysRoleMenu.setRoleId(roleId);
            sysRoleMenu.setMenuId(m);
            return sysRoleMenu;
        }).collect(Collectors.toList());
        return this.saveBatch(list);
    }

    @Override
    public boolean deleteByRoleId(Long roleId){
        LambdaQueryWrapper<DapSysRoleMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DapSysRoleMenu::getRoleId,roleId);
        return this.remove(wrapper);
    }
}
